﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DHLPricing
{
    public partial class Pricing : Form
    {
        List<KF.DHLModel.ZoneInfo> zoneInfos;
        List<KF.DHLModel.PriceInfo> priceInfos;

        public Pricing()
        {
            InitializeComponent();

            KF.DHLBL.ZoneInfo zoneBL = new KF.DHLBL.ZoneInfo();
            KF.DHLBL.PriceInfo priceBL = new KF.DHLBL.PriceInfo();
            zoneInfos = zoneBL.GetZoneInfo();
            priceInfos = priceBL.GetPriceInfo();
        }

        private void Pricing_Load(object sender, EventArgs e)
        {
            cbType.Items.Insert(0, "普通");
            cbType.Items.Insert(1, "VIP");
            cbType.SelectedIndex = 0;

            cbItemType.Items.Insert(0, "普通");
            cbItemType.Items.Insert(1, "文件");
            cbItemType.SelectedIndex = 0;


            cbCountry.DataSource = zoneInfos;
            cbCountry.DisplayMember = "NameS";
            cbCountry.ValueMember = "Zone";

            string[] suggestTxt = new string[zoneInfos.Count];

            for (int i = 0; i < zoneInfos.Count; i++)
            {
                suggestTxt[i] = zoneInfos[i].NameS;
            }
            cbCountry.AutoCompleteCustomSource.AddRange(suggestTxt);

        }

        private void btnCalc_Click(object sender, EventArgs e)
        {
            KF.DHLModel.ItemType itemtype = KF.DHLModel.ItemType.NO;
            if(cbItemType.SelectedText == "文件")
            {
                itemtype = KF.DHLModel.ItemType.DOC;
            }

            KF.DHLModel.CustomerType customertype = KF.DHLModel.CustomerType.NO;
            if(cbItemType.SelectedText == "VIP")
            {
                customertype = KF.DHLModel.CustomerType.VIP;
            }

            KF.DHLBL.Prcing p = new KF.DHLBL.Prcing();

            double price = p.CalcPrice(priceInfos, (int)cbCountry.SelectedValue, Convert.ToDouble(tbWeight.Text),
               itemtype, customertype);
            tbPrice.Text = price.ToString();
        }
    }
}
